import openpyxl



def read_excel():
    '''读取excel表的数据'''
    wb = openpyxl.load_workbook("./Data/IP列表.xlsx")
    sh = wb["Sheet1"]
    res = list(sh.rows)

    # 获取表头
    titles = [title.value for title in res[0]]

    # 创建容器
    cons = []

    for data in res[1:]:
        da = [i.value for i in data]
        dic = dict(zip(titles,  da))
        cons.append(dic)
    return cons


def write_excel(values):
    column = 3

    wb = openpyxl.load_workbook("./Data/IP列表.xlsx")
    sh = wb["Sheet1"]
    values_size = len(values)

    for i in range(1,  values_size+1,  1):
        sh.cell(row=i+1,  column=column,  value=values[i-1])

    wb.save("./report/IP状态列表.xlsx")


